package com.hndzyu.yd.vip;

import android.annotation.SuppressLint;
import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.hndzyu.yd.R;
import com.hndzyu.yd.url.Path;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by YJ on 2018/10/23.
 */
public class HairCircleAdapter extends RecyclerView.Adapter<HairCircleAdapter.ViewHolder> {
    private Context mContext;
    private List<CircleListBean.DataBean> mData = new ArrayList<>();
    private HairCircleListener mListener;

    public void setListener(HairCircleListener listener) {
        mListener = listener;
    }

    public HairCircleAdapter(Context context) {
        mContext = context;
    }

    public void updateData(int page, List<CircleListBean.DataBean> dataSet) {
        if (dataSet != null && !dataSet.isEmpty()) {
            if (page == 1){
                mData = dataSet;
            } else {
                mData.addAll(dataSet);
            }
            notifyDataSetChanged();
        }
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.item_hair_circle, parent, false);
        return new ViewHolder(view);
    }

    @SuppressLint("SetTextI18n")
    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        final CircleListBean.DataBean dataBean = mData.get(position);
        holder.tvContent.setText(dataBean.getTitle());
        holder.tvMoney.setText("" + (double)dataBean.getKeeptime()/3600 + "小时");
        holder.tvTime.setText((Html.fromHtml("预计赚：" + "<font color=\"#FF0000\">¥"+dataBean.getMaxget()+"</font>")));
        Glide.with(mContext).load(Path.BASE_URL + dataBean.getLogo()).into(holder.iv);
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mListener.itemClick(dataBean);
            }
        });
    }

    @Override
    public int getItemCount() {
        return mData.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        TextView tvContent;
        TextView tvTime;
        TextView tvMoney;
        ImageView iv;
        public ViewHolder(View itemView) {
            super(itemView);
            tvContent = itemView.findViewById(R.id.tv_content);
            tvTime = itemView.findViewById(R.id.tv_time);
            tvMoney = itemView.findViewById(R.id.tv_money);
            iv = itemView.findViewById(R.id.iv);
        }
    }
    public interface HairCircleListener{
        void itemClick(CircleListBean.DataBean bean);
    }
}
